@extends('admin.layouts.app')

@section('right-content')
    <fieldset class="layui-elem-field layui-field-title">
        <legend>
        <span class="layui-breadcrumb">
            <a href="javascript:;">游戏管理</a>
            <a><cite>每日任务列表</cite></a>
        </span>
        </legend>
    </fieldset>

    <table id="dateTable" class="layui-table">
        <thead>
        <tr>
            <th><input type="checkbox" class="my-checkbox" /></th>
            <th>序号</th>
            <th>类别</th>
            <th>名称</th>
            <th>描述</th>
            <th>目标值</th>
            <th>积分奖励</th>
            <th>筹码奖励</th>
            <th>排序</th>
            <th>全平台广播</th>
            <th>触发分享</th>
            <th>图片</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        @foreach($daliy_missions as $key => $value)
            <tr>
                <td><input type="checkbox" class="my-checkbox" data-id="{{ $value->id }}" /></td>
                <td>{{ $key + 1 }}</td>
                <td>{{ $value->condition_kind }}</td>
                <td>{{ $value->name }}</td>
                <td>{{ $value->description }}</td>
                <td>{{ $value->dest_value }}</td>
                <td>{{ $value->prize_gift_score }}</td>
                <td>{{ $value->prize_jeton }}</td>
                <td>{{ $value->listorder }}</td>
                <td>@if($value->broadcast == 1) 是 @else 否 @endif</td>
                <td>@if($value->triggle_share == 1) 是 @else 否 @endif</td>
                <td>{{ $value->icon }}</td>
                <td>@if($value->status == 1) 上线 @else 下线 @endif</td>
                <td>
                    <button class="layui-btn layui-btn-small layui-btn-normal edit" data-url="{{ route('daliyMissions.edit', ['id' => $value->id]) }}">编辑</button>
                    <button class="layui-btn layui-btn-small layui-btn-danger delete" data-url="{{ route('daliyMissions.destroy', ['id' => $value->id]) }}">删除</button>
                </td>
            </tr>
        @endforeach
        </tbody>
    </table>

@endsection

@section('my-js')
    <script type="text/javascript" src="http://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="{{ asset('admin/js/table-tool.js') }}"></script>
    <script type="text/javascript">
        layui.use(['element','layer'], function(){
            var $ = layui.jquery,element = layui.element,layer = layui.layer;

            // 初始化表格
            $('#dateTable').DataTable({
                "dom": '<"top"f>rt<"bottom"lp><"clear">',
                "autoWidth": false,                     // 自适应宽度
                "stateSave": true,                      // 刷新后保存页数
                "order": [[ 1, "desc" ]],               // 排序
                "searching": true,                     // 本地搜索
                "info": true,                           // 控制是否显示表格左下角的信息
                "stripeClasses": ["odd", "even"],       // 为奇偶行加上样式，兼容不支持CSS伪类的场合
                "aoColumnDefs": [{                      // 指定列不参与排序
                    "orderable": false,
                    "aTargets": [0,1,2,3,4,5,6,7,8,9,10,11,12,13]                   // 对应你的表格的列数
                }],
                "pagingType": "simple_numbers",         // 分页样式 simple,simple_numbers,full,full_numbers
                "language": {                           // 国际化
                    "url":'{{ asset('admin/language.json') }}'
                },
                initComplete: function() {
                    $('.top').append('<span class="fl"><a class="layui-btn btn-add btn-default" id="btn-add-article" href="{{ route('daliyMissions.create') }}">添加任务</a><a class="layui-btn layui-btn-danger radius btn-delect" id="btn-delete-all">批量删除</a></span>');
                }
            });

            // 例:获取ids
            $(document).on('click','#btn-delete-all', function(){
                // getIds(table对象,获取input为id的属性)
                var list = getIds($('#dateTable'),'data-id');
                if(list == null || list == ''){
                    layer.msg('未选择');
                }else{
                    // layer.msg(list);
                    layer.confirm('is not?', {icon: 3, title:'提示', content:'您确定要删除吗？'}, function(index){
                        layer.close(index);
                        $.post("{{ route('daliyMissions.destroyList') }}", {ids : list}, function(data) {
                            console.log(data);
                            if (data.status == 0) {
                                top.layer.msg(data.msg, {icon: 1, time: 2000});
                                window.location.href=data.url;
                            } else {
                                top.layer.msg(data.msg, {icon: 2, time: 2000});
                                window.location.reload();
                            }
                        },'json');
                    });
                }
            });

            $(document).on('click','.edit', function(){
                var url = $(this).attr('data-url');
                window.location.href = url;
            });

            $(document).on('click','.delete', function(){
                var url = $(this).attr('data-url');
                commonAjaxRequest(url, 'DELETE')
            });


        });
    </script>

@endsection